package com.android.uu.view.HorizontalSlideListView;

import android.app.Activity;
import android.content.Context;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;

/**用于可以展开的ListView的适配器Adapter的拓展
 * @author GuiyouZhang
 * Date:2015-08-31
 */
public class UUHorizontalSlideExpandableAdapter extends BaseExpandableListAdapter {
	
	/** 记录滑动出删除按钮的itemView */
	public HorizontalScrollView mScrollView;
	/** 布局参数,动态让HorizontalScrollView中的TextView宽度包裹父容器 */
	private LinearLayout.LayoutParams mParams;
	private int mScreenWidth;/** 屏幕宽度 */
	/** touch事件锁定,如果已经有滑动出删除按钮的itemView,就屏蔽下一整次(down,move,up)的onTouch操作 */
	//主要是屏幕同时按下，同时滑出两个item的情况
	public boolean mLockOnTouch = false;
	
	public UUHorizontalSlideExpandableAdapter(Context context) {
		super();
		// 搞到屏幕宽度
		Display defaultDisplay = ((Activity) context).getWindowManager()
				.getDefaultDisplay();
		DisplayMetrics metrics = new DisplayMetrics();
		defaultDisplay.getMetrics(metrics);
		mScreenWidth = metrics.widthPixels;
		mParams = new LinearLayout.LayoutParams(mScreenWidth, LinearLayout.LayoutParams.MATCH_PARENT);
	}

	/**初始化控件
	 * @param scrollview 每个item的水平滑动scrollview
	 * @param front 在没有滑动时，默认填满手机屏幕的view
	 */
	public void initViews(UUHorizontalExpandableScrollView scrollview, View front) {
		scrollview.setAdapter(this);
		scrollview.setFadingEdgeLength(0);//设置滑动的阴影不显示
		scrollview.setOverScrollMode(View.OVER_SCROLL_NEVER);
		front.setLayoutParams(mParams);//设置前面的view填满手机屏幕
	}

	/** HorizontalScrollView左右滑动 */
	public void scrollView(final HorizontalScrollView view, final int parameter) {
		Log.d("uu", "调用滑出");
		//通过设置水平轴的焦点在最左or最右来
		view.post(new Runnable() {
			@Override
			public void run() {
				view.pageScroll(parameter);
			}
		});
	}
	
	@Override
	public int getGroupCount() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int getGroupTypeCount() {
		// TODO Auto-generated method stub
		return 2;
	}

	@Override
	public int getChildrenCount(int groupPosition) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public Object getGroup(int groupPosition) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object getChild(int groupPosition, int childPosition) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getGroupId(int groupPosition) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public long getChildId(int groupPosition, int childPosition) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public boolean hasStableIds() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public View getGroupView(int groupPosition, boolean isExpanded,
			View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public View getChildView(int groupPosition, int childPosition,
			boolean isLastChild, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean isChildSelectable(int groupPosition, int childPosition) {
		// TODO Auto-generated method stub
		return false;
	}
}
